//
//  MySelfVC.m
//  MyProject
//
//  Created by jiaming yan on 2018/3/14.
//  Copyright © 2018年 yanjiaming. All rights reserved.
//

#import "MySelfVC.h"
#import "UserInfoVC.h"
#import "MyServiceVC.h"
#import "MyOrderListVC.h"
#import "BuyOrderListVC.h"
#import "MyCollectionVC.h"
#import "MyWalletVC.h"
#import "MyRefundViewController.h"
#import "BeenViewedListVC.h"
#import "UIButton+WebCache.h"
#import "NSUDManager.h"
#import <MJExtension.h>
#import "VitaeVC.h"
#import "TaijieBiVC.h"
#import "SettingVC.h"
#import "CertificationViewController.h"
#import "HelpViewController.h"
#import "CompanyInfoCertificateVC.h"
#import "AuthenticationStateModel.h"
#import "CompanyReviewViewController.h"
#import "AuthenticationFailVC.h"
#import "AuthenticationSuccessVC.h"

@interface MySelfVC ()
@property (weak, nonatomic) IBOutlet UIScrollView *scollView;
@property (weak, nonatomic) IBOutlet UIButton *headButton;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topViewHeight;

@property (weak, nonatomic) IBOutlet UILabel *authenticationLabel;
@property (strong, nonatomic) AuthenticationStateModel *authenticationModel;

@end

@implementation MySelfVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.headButton.imageView.contentMode = UIViewContentModeScaleAspectFill;
    // Do any additional setup after loading the view from its nib.
    self.navigationController.navigationBarHidden = YES;
    if (@available(iOS 11.0, *)) {
        self.scollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        // Fallback on earlier versions
    }
    if (IOS11Later) {
        self.topViewHeight.constant = 0;
    }else{
        self.topViewHeight.constant = 20;
    }
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    UserModel *user = [NSUDManager currentUser];
    [self.headButton sd_setImageWithURL:[NSURL URLWithString:ImageURL(user.headImg)] forState:UIControlStateNormal placeholderImage:IMAGE(@"默认图")];
    self.nameLabel.text = user.nickName;
    if ([self.authenticationLabel.text isEqualToString:@"已认证"]) {
        
    }else{
        [self authentication];
    }
    
}
- (IBAction)settingClick:(id)sender {
    SettingVC *vc = [[SettingVC alloc]init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}
/*
 方法描述:
 认证状态
 
 参数说明:
 <#参数说明#>
 
 返回结果:
 <#返回结果#>
 
 */
-(void)authentication{
//    [self showProgressWithView:self.view animated:YES];
    [YJMSendRequest postDataWithParameters:@{} url:@"incumbent/getIncumbentStateOfAuthentication" result:^(NSDictionary *result, NSError *error) {
        result = [CommonUtils decryptDicWithResult:result];
        [self hideProgress:self.view animated:YES];
        if([result[@"result"] integerValue] == 1)
        {
            NSInteger isAuthentication = [result[@"data"][@"state"] integerValue];
//            if (isAuthentication == 1) {
//                self.authenticationLabel.text = @"已认证";
//            }else{
//                self.authenticationLabel.text = @"未认证";
//            }
//
            self.authenticationModel = [AuthenticationStateModel mj_objectWithKeyValues:result[@"data"][@"authenticationInfo"]];
            if ([self.authenticationModel.reviewState isEqualToString:@"INCUMBENT_UNCOMMITTED"]) {
                self.authenticationLabel.text = @"未认证";
            }else if ([self.authenticationModel.reviewState isEqualToString:@"INCUMBENT_IN_REVIEW"]) {
                self.authenticationLabel.text = @"审核中";
            }else if ([self.authenticationModel.reviewState isEqualToString:@"INCUMBENT_SUCCESS"]) {
                
                if (self.authenticationModel.companyId.length == 0) {
                    self.authenticationLabel.text = @"已认证";
                }else{
                    self.authenticationLabel.text = @"给公司打分";
                }
            }else if ([self.authenticationModel.reviewState isEqualToString:@"INCUMBENT_FAILED"]) {
                self.authenticationLabel.text = @"认证失败";
            }
        }else{
            [CommonUtils showToast:[result objectForKey:@"msg"]];
        }
       
    }];
    
}
- (IBAction)headButtonClick:(id)sender {
    UserInfoVC *vc = [[UserInfoVC alloc]init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}
- (IBAction)topButtonClick:(UIButton *)sender {
    switch (sender.tag) {
        case 1:
        {
            /**微简历*/
            
            VitaeVC *vc = [[VitaeVC alloc]init];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
            
        }
            break;
        case 2:
        {
            /**已购服务*/
            BuyOrderListVC *vc = [[BuyOrderListVC alloc]init];
            vc.isBuyType = 0;
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 3:
        {
            
            /**我的收藏*/
            
            MyCollectionVC *vc = [[MyCollectionVC alloc]init];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        default:
            break;
    }
}

- (IBAction)bottomButonClick:(UIButton *)sender {
    switch (sender.tag) {
        case 1:
        {
            /**申请认证*/
            if ([self.authenticationModel.reviewState isEqualToString:@"INCUMBENT_UNCOMMITTED"]) {
                CompanyInfoCertificateVC *vc = [[CompanyInfoCertificateVC alloc] init];
                UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
                [self presentViewController:nav animated:YES completion:nil];
                
            }else if ([self.authenticationModel.reviewState isEqualToString:@"INCUMBENT_IN_REVIEW"]) {
                self.authenticationLabel.text = @"审核中";
                ALERT_VIEW(@"认证审核中，请耐心等待");
            }else if ([self.authenticationModel.reviewState isEqualToString:@"INCUMBENT_SUCCESS"]) {
                
                if (self.authenticationModel.companyId.length == 0) {
                    self.authenticationLabel.text = @"已认证";
                }else{
                    self.authenticationLabel.text = @"给公司打分";
                    AuthenticationSuccessVC *vc = [[AuthenticationSuccessVC alloc]init];
                    vc.hidesBottomBarWhenPushed = YES;
                    vc.authenticationModel = self.authenticationModel;
                    [self.navigationController pushViewController:vc animated:YES];
                    
                }
            }else if ([self.authenticationModel.reviewState isEqualToString:@"INCUMBENT_FAILED"]) {
                self.authenticationLabel.text = @"认证失败";
                AuthenticationFailVC *vc = [[AuthenticationFailVC alloc]init];
                vc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:vc animated:YES];
            }
            
//            if ([self.authenticationLabel.text isEqualToString:@"已认证"]) {
//                
//            }else{
////                CertificationViewController *vc = [[CertificationViewController alloc] init];
//                CompanyInfoCertificateVC *vc = [[CompanyInfoCertificateVC alloc] init];
//                UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
//                [self presentViewController:nav animated:YES completion:nil];
//            }
           
        }
            break;
        case 2:
        {
            /**我的钱包*/
            
            MyWalletVC *vc = [[MyWalletVC alloc]init];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 3:
        {
            /**我的退款*/
            
            MyRefundViewController *vc = [[MyRefundViewController alloc]init];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 4:
        {
            /**台阶币*/
            
            TaijieBiVC *vc = [[TaijieBiVC alloc]init];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 5:
        {
            /**我的服务*/
            MyServiceVC *vc = [[MyServiceVC alloc]init];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 6:
        {
            /**服务订单*/
            BuyOrderListVC *vc = [[BuyOrderListVC alloc]init];
            vc.isBuyType = 1;
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
            
            
            //            MyOrderListVC *vc = [[MyOrderListVC alloc]init];
            //            vc.hidesBottomBarWhenPushed = YES;
            //            [self.navigationController pushViewController:vc animated:YES];
            
        }
            break;
        case 7:
        {
            /**帮助与反馈*/
            
            HelpViewController *vc = [[HelpViewController alloc]init];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        default:
            break;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
